package org.millioncall.yueyoga.admin.service.impl;

import java.util.List;
import java.util.Map;

import org.millioncall.openplatform.common.PaginatedList;
import org.millioncall.yueyoga.admin.dao.ProductDAO;
import org.millioncall.yueyoga.admin.model.AviatorExpression;
import org.millioncall.yueyoga.admin.model.ConsumeHistoryModel;
import org.millioncall.yueyoga.admin.model.Product;
import org.millioncall.yueyoga.admin.service.ProductService;

public class ProductServiceImpl implements ProductService {

	private ProductDAO productDAO;

	public ProductDAO getProductDAO() {
		return productDAO;
	}

	public void setProductDAO(ProductDAO productDAO) {
		this.productDAO = productDAO;
	}

	@Override
	public Product findById(Map<String, Object> map) {
		return this.productDAO.findById(map);
	}

	@Override
	public PaginatedList<Product> findInPage(Map<String, Object> map,
			int pageNo, int pageSize) {
		return this.productDAO.findInPage(map, pageNo, pageSize);
	}

	@Override
	public PaginatedList<Product> findInPage(int pageNo, int pageSize) {
		return this.productDAO.findInPage(pageNo, pageSize);
	}

	@Override
	public int save(Product product) {
		return this.productDAO.save(product);
	}

	@Override
	public int update(Product product) {
		return this.productDAO.update(product);
	}

	@Override
	public int delete(Product product) {
		return this.productDAO.delete(product);
	}

	@Override
	public int deleteByIds(String[] ids) {
		int del = 0;
		if (ids == null || ids.length == 0) {
			throw new RuntimeException(" 未提交要删除产品的编号");
		} else {
			try {
				del = this.productDAO.deleteByIds(ids);
				return del;
			} catch (Exception e) {
				return 0;
			}
		}
	}

	@Override
	public PaginatedList<Product> findAll() {
		return this.productDAO.findAll();
	}

	@Override
	public PaginatedList<Product> findProductAvailable(int pageNo,
			int pageSize, Map<String, Object> map) {
		return this.productDAO.findProductAvailable(pageNo, pageSize, map);
	}

	@Override
	public List<Product> findProductAvailableAll(Map<String, Object> map) {
		return this.productDAO.findProductAvailableAll(map);
	}

	@Override
	public PaginatedList<Product> findByMemberIdInPage(Integer memberId,
			int start, int limit) {
		return this.productDAO.findByMemberIdInPage(memberId, start, limit);
	}

	@Override
	public PaginatedList<ConsumeHistoryModel> findAllConsumeHistory(
			Map<String, Object> params, Integer pageNo, Integer pageSize) {
		return this.productDAO.findAllConsumeHistory(params, pageNo, pageSize);
	}

	@Override
	public PaginatedList<ConsumeHistoryModel> findAllAbsentForSomeDays(
			Map<String, Object> params, Integer pageNo, Integer pageSize) {
		return this.productDAO.findAllAbsentForSomeDays(params, pageNo,
				pageSize);
	}

	@Override
	public PaginatedList<Product> findProductAvailable(Map<String, Object> map,
			int pageNo, int pageSize) {
		return this.productDAO.findProductAvailable(map, pageNo, pageSize);
	}

	@Override
	public PaginatedList<Product> findMemberInfoInPage(Map<String, Object> map,
			Integer start, Integer limit) {
		return this.productDAO.findMemberInfoInPage(map, start, limit);
	}

	@Override
	public List<Product> getAllProductsWithAviator(Map<String, Object> params,
			AviatorExpression expression, Map<String, Object> aviatorParams,
			int limit) {
		return this.productDAO.getAllProductsWithAviator(params, expression,
				aviatorParams, limit);
	}

	@Override
	public void clearWeeklyUseTimes() {
		this.productDAO.clearWeeklyUseTimes();
	}
}
